package com.song.Inet.Socket2;

import java.io.*;
import java.net.InetAddress;
import java.net.Socket;

/**
 * @Author ZhangGuisong
 * @Date 2021/5/4-12:01
 */
public class SoketClient {
    public static void main(String[] args) throws Exception {
        Socket socketClient=new Socket(InetAddress.getLocalHost(),1996);
        OutputStream outputStream = socketClient.getOutputStream();
        //从磁盘上读取图片
        BufferedInputStream bufferedInputStream=new BufferedInputStream
                (new FileInputStream("D:/360downloads/wpcache/360wallpaper.jpg"));
        byte[] bytes = StreamUtils.streamToByteArray(bufferedInputStream);
        //将读取的图片写入到socket通道
        BufferedOutputStream bufferedOutputStream=new BufferedOutputStream(outputStream);
        bufferedOutputStream.write(bytes);
        socketClient.shutdownOutput();
        //接收server 端信息
        InputStream inputStream = socketClient.getInputStream();
        BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(inputStream));
        String s = bufferedReader.readLine();
        System.out.println(s);
        //关闭资源
        bufferedOutputStream.close();
        bufferedInputStream.close();
        outputStream.close();
        socketClient.close();



    }
}
